<template>
	<view>
		你好
		<view class="h-120"></view>
		<view @click="stopWS">手动关闭</view>
		<view class="h-120"></view>
		<view @click="sendChat('呼交..')">手动发送</view>
	</view>
</template>

<script setup>
	import { onLoad, onUnload, onShow, onHide } from '@dcloudio/uni-app';
	import { ref } from 'vue';
	import wsRequest from "@/until/websocket.js"
	const socket = ref(new wsRequest(''))

	//onLoad
	onLoad((option) => {
		socket.value.onConnected = () => {
			
			watchSocket()
		}
	})

	//onUnload
	onUnload(() => {
		socket.value.close({
			reason: '用户自己关闭'
		})
	})

	// 手动关闭
	const stopWS = async (data) => {
		console.log('stopWS...')
		socket.value.close({
			reason: '用户自己关闭'
		})
	}
	

	//发送
	const sendChat = async (data) => {
		let modal = {
			msgContent: {
				consumeCode: "",
				memberCode: "M00050000318",
				memberName: "微187****0108",
				orderInfo: {
					attachment: "https://oss.jtmckj.com/backend/OrgGoods/2024101910380580歌手·阿村.jpg",
					flavor: "",
					goodsCode: "P000501",
					goodsName: "歌手·阿村",
					goodsType: "001818",
					groupCode: "001818",
					isEstmClear: "0",
					isJoinMinConsume: "1",
					isUseGold: "0",
					itemCode: "0018P000501041047",
					mathType: "plus",
					num: 2,
					orgCode: "0018",
					producePoint: "001803",
					saleCoins: "0",
					saleLimitMax: 999,
					saleLimitMin: 0,
					saleLimitStep: 1,
					salePrice: "200.00",
					saleQty: "13",
					state: "1",
					type: "1",
					uomCode: "041047",
					uomName: "首",
					vipPrice: "200.00"
				},
				roomCode: "0018018"
			},
			msgPlatform: 3,
			msgType: "message"
		} 
		socket.value.send(JSON.stringify(modal));
	}

	//接收 
	const watchSocket = () => {
		socket.value.getMessage(opt => {
			console.log("消息接收：", opt);
		})
	}
</script>



